package cn.edu.imust.loginregisterdemo.base;

import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import cn.edu.imust.loginregisterdemo.MyApplication;

public class BaseFragment extends Fragment implements View.OnTouchListener {

    private FragmentActivity mActivity;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        mActivity = getActivity();
    }

    @Nullable
    @Override
    public Context getContext() {
        if (mActivity == null) {
            return MyApplication.getContext();
        }
        return mActivity;
    }


    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }

    /**
     * 防止点击穿透*/
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        // 拦截触摸事件，防止泄露下去
        view.setOnTouchListener(this);
    }
}
